package com.zhouxianglh.week156;

public class Second {
    public static void main(String[] args) {
        // System.out.println(equalSubstring("abcd", "bcdf", 3));
        // System.out.println(equalSubstring("abcd", "cdef", 3));
        // System.out.println(equalSubstring("abcd", "acde", 0));
        System.out.println(equalSubstring("pxezla", "loewbi", 25));
    }

    public static int equalSubstring(String s, String t, int maxCost) {
        if (s.length() == 0) {
            return 0;
        }
        int[] intArr = new int[s.length()];
        for (int i = 0, j = s.length(); i < j; i++) {
            int count = Math.abs(s.charAt(i) - t.charAt(i));
            intArr[i] = count;
        }
        int max = 0;
        for (int i = 0, j = s.length(); i < j; i++) {
            if (intArr[i] <= maxCost) {
                int cost = maxCost - intArr[i];
                int flag = 1;
                for (int m = i + 1; m < j; m++) {
                    if (intArr[m] <= cost) {
                        cost = cost - intArr[m];
                        flag++;
                    } else {
                        break;
                    }
                }
                max = Math.max(max, flag);
            }
        }
        return max;
    }
}
